package com.rengl.ssmmvc.controller;

import com.rengl.ssmmvc.common.Result;
import com.rengl.ssmmvc.model.User;
import com.rengl.ssmmvc.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("hi")
    public String hi(){
        return "hi";
    }

    @PostMapping("add")
    public Result add(@RequestBody User user){

        userService.add(user);
        return Result.ok();
    }

    @GetMapping("list")
    private Result list(){
        List<User> userList = userService.list();
        return Result.ok(userList);
    }
}
